import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../../base/BasePage.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:tot_android_flutter/utils/utils_ext.dart';
import 'package:tot_android_flutter/common/widget/CommonWidget.dart';
import 'package:tot_android_flutter/common/widget/RefreshWrapper.dart';
import '../../../../eneity/project_list_entity.dart';
import 'projcet_list_controller.dart';

class ProjectListPage extends BasePage<ProjectListController> {
  final int cid;

  ProjectListPage(this.cid, {super.key})
      :super(tag: "ProjectListController-${cid}");

  final EasyRefreshController _refreshController = EasyRefreshController(
    controlFinishRefresh: true,
    controlFinishLoad: true,
  );

  @override
  void preInit() {
    super.preInit();
    controller.cid = cid;
    controller.refreshController = _refreshController;
  }


  @override
  Widget buildBody(BuildContext context) {
    return RefreshWrapper(
        onRefresh: controller.refreshPaging,
        onLoad: controller.loadMorePaging,
        controller: _refreshController,
        child: (context, physics) {
          return Obx(() {
            return  GridView.builder(
                physics: physics,
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisSpacing: 8,
                  mainAxisSpacing: 8,
                  crossAxisCount: 2,
                  childAspectRatio: 2 / 3.3,
                ),
                itemCount: controller.projectLists.length,
                itemBuilder: (context, index) {
                  return _generateItem(controller.projectLists[index]);
                });
          });
        });
  }

  Widget _generateItem(ProjectListDataDatas item) {
    return Card(
        color: Colors.white,
        elevation: 2,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(20.w),
        ),
        child: ClipRRect(
          borderRadius: BorderRadius.all(Radius.circular(20.w)),
          child: Stack(
            children: [
              Image.network(
                item.envelopePic,
                fit: BoxFit.fill, // 填满整个Stack
                width: double.infinity, // 宽度尽可能大
                height: double.infinity, // 高度尽可能大
              ),
              Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: Container(
                    color: Colors.black45,
                    padding: EdgeInsets.fromLTRB(6.w, 3.w, 6.w, 6.w),
                    child: titleHtmlView(item.title, Colors.white),
                  ))
            ],
          ),
        ));
  }
}
